// const query = require('../util/query')
const {Util} = require('../util/util')
const Bodyparser = require('koa-bodyparser')
// const Redis = require('../util/redisConnect') 

const User = {

   //登陆API
   login: async(ctx) =>{
	try {
		const body = ctx.request.body
		const username = body.username
		const password = body.password
		
		let payload = {
			'username': username, 
			'password': password
		}
	
		let getToken = Util.setToken(payload, 60 * 5)

		ctx.response.body = {
			'code': 0,
			'msg': 'ok',
			'data': {
				'token': getToken
			}
		}
		  
	}catch (e) {
		ctx.response.body = {
			'code': -1,
			'msg': '接口调用失败，请联系帅气的管理员',
		}
	}
   },

   self: async(ctx) => {
	   try {
			ctx.response.body = {
				'msg':'success',
				'code': 0		
			}
		} catch(e) {
			ctx.response.body = {
				'code': -1,
				'msg': '接口调用失败，请联系帅气的管理员',
		  }
	   }
   },
}

module.exports = {
    User
}

